<?php
/**
 * Created by PhpStorm.
 * User: 86188
 * Date: 2020/11/17
 * Time: 16:54
 */

namespace app\service;
use think\facade\Db;



class BillService
{
    public function billRoomIdList($community_id,$out_room_id){

        return DB::table('bill')
            ->where('community_id',$community_id)
            ->where('out_room_id',$out_room_id)
            ->where('status','WAIT_PAY')
            ->select();
    }

    public function cost_type($community_id,$out_room_id){
        $cost_type = DB::table('bill')
            ->where('community_id',$community_id)
            ->where('out_room_id',$out_room_id)
            ->where('status','WAIT_PAY')
            ->distinct()
            ->column('cost_type');

        return $cost_type;
    }

    //根据种类查账单
    public function cost_type_bill($community_id,$out_room_id,$b){
        $field=array("id","cost_type","bill_date_desc as acct_period","bill_amount as bill_entry_amount","room_address");
        $cost_type_bill = DB::table('bill')
            ->where('community_id',$community_id)
            ->where('out_room_id',$out_room_id)
            ->where('status','WAIT_PAY')
            ->where('cost_type',$b)
            ->field($field)
            ->select();
        return $cost_type_bill ;
    }

    //查询指定id是否存在
    public function billEntryIdInfo($data){
        return DB::table('bill')->whereIn('id',$data)->select();
    }


    //根据communityid获取token
    public function token($community_id){
        $propertyShortName = DB::table('community')->where('community_id',$community_id)->value('propertyShortName');
        return DB::table('property')->where('propertyShortName',$propertyShortName)->value('accredit');
    }

    //修改指定账单数据
    public function billEdit($data,$billid){
        return DB::table('bill')->where("id",$billid)->update($data);
    }

    public function  costTypeName($costType){
        return DB::table('costtype')->where('type',$costType)->value('cost_name');
    }
}
